﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ValidationFramework.Reflection;

namespace ValidationFramework
{
	public class Rules
	{
		/// <summary>
		/// Initializes a new instance of the Rules class.
		/// </summary>
		public Rules(RuntimeTypeHandle parentHandle, RuntimeTypeHandle childHandle)
		{
			ParentScopedRules = new RuleCollection(parentHandle);
			MemberScopedRules = new RuleCollection(childHandle);
		}
		/// <summary>
		/// Gets or sets the parent scoped rules for this chached member
		/// </summary>
		public RuleCollection ParentScopedRules
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the member scoped rules for this chached member
		/// </summary>
		public RuleCollection MemberScopedRules
		{
			get;
			set;
		}

		public Rule AddRule(Rule rule, RuleScope scope)
		{
			if (scope == RuleScope.Parent)
				return ParentScopedRules.AddNew(rule);
			else
				return MemberScopedRules.AddNew(rule);
		}

		public void Merge(Rules rules)
		{
			MemberScopedRules.Merge(rules.MemberScopedRules);
			ParentScopedRules.Merge(rules.ParentScopedRules);
		}
	

		/// <summary>
		/// Gets the total number of rules this descriptor containes
		/// </summary>
		public int Count
		{
			get
			{
				return MemberScopedRules.Count + ParentScopedRules.Count;
			}
		}
	}
}
